package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.system.domain.EmployeeBasicInfo;
import com.ruoyi.system.mapper.PersonalAwardsMapper;
import com.ruoyi.system.domain.PersonalAwards;
import com.ruoyi.system.service.IPersonalAwardsService;

/**
 * 个人奖励情况Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-05-22
 */
@Service
public class PersonalAwardsServiceImpl implements IPersonalAwardsService 
{
    @Autowired
    private PersonalAwardsMapper personalAwardsMapper;

    /**
     * 查询个人奖励情况
     * 
     * @param id 个人奖励情况主键
     * @return 个人奖励情况
     */
    @Override
    public PersonalAwards selectPersonalAwardsById(String id)
    {
        return personalAwardsMapper.selectPersonalAwardsById(id);
    }

    /**
     * 查询个人奖励情况列表
     * 
     * @param personalAwards 个人奖励情况
     * @return 个人奖励情况
     */
    @Override
    public List<PersonalAwards> selectPersonalAwardsList(PersonalAwards personalAwards)
    {
        return personalAwardsMapper.selectPersonalAwardsList(personalAwards);
    }

    /**
     * 新增个人奖励情况
     * 
     * @param personalAwards 个人奖励情况
     * @return 结果
     */
    @Transactional
    @Override
    public int insertPersonalAwards(PersonalAwards personalAwards)
    {
        int rows = personalAwardsMapper.insertPersonalAwards(personalAwards);
        insertEmployeeBasicInfo(personalAwards);
        return rows;
    }

    /**
     * 修改个人奖励情况
     * 
     * @param personalAwards 个人奖励情况
     * @return 结果
     */
    @Transactional
    @Override
    public int updatePersonalAwards(PersonalAwards personalAwards)
    {
        personalAwardsMapper.deleteEmployeeBasicInfoByEmployeeId(personalAwards.getId());
        insertEmployeeBasicInfo(personalAwards);
        return personalAwardsMapper.updatePersonalAwards(personalAwards);
    }

    /**
     * 批量删除个人奖励情况
     * 
     * @param ids 需要删除的个人奖励情况主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deletePersonalAwardsByIds(String[] ids)
    {
        personalAwardsMapper.deleteEmployeeBasicInfoByEmployeeIds(ids);
        return personalAwardsMapper.deletePersonalAwardsByIds(ids);
    }

    /**
     * 删除个人奖励情况信息
     * 
     * @param id 个人奖励情况主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deletePersonalAwardsById(String id)
    {
        personalAwardsMapper.deleteEmployeeBasicInfoByEmployeeId(id);
        return personalAwardsMapper.deletePersonalAwardsById(id);
    }

    /**
     * 新增员工基本信息信息
     * 
     * @param personalAwards 个人奖励情况对象
     */
    public void insertEmployeeBasicInfo(PersonalAwards personalAwards)
    {
        List<EmployeeBasicInfo> employeeBasicInfoList = personalAwards.getEmployeeBasicInfoList();
        String id = personalAwards.getId();
        if (StringUtils.isNotNull(employeeBasicInfoList))
        {
            List<EmployeeBasicInfo> list = new ArrayList<EmployeeBasicInfo>();
            for (EmployeeBasicInfo employeeBasicInfo : employeeBasicInfoList)
            {
                employeeBasicInfo.setEmployeeId(id);
                list.add(employeeBasicInfo);
            }
            if (list.size() > 0)
            {
                personalAwardsMapper.batchEmployeeBasicInfo(list);
            }
        }
    }
}
